package cn.wolfcode.luowowo.mgrsite.controller;

import cn.wolfcode.luowowo.article.domain.TravelContent;
import cn.wolfcode.luowowo.article.query.TravelQuery;
import cn.wolfcode.luowowo.article.service.ITravelService;
import cn.wolfcode.luowowo.common.util.AjaxResult;
import com.alibaba.dubbo.config.annotation.Reference;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Component;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Component
@RequestMapping("travel")
public class TravelController {

    @Reference
    private ITravelService travelService;


    /**
     * 查询分页
     * @param model
     * @param qo
     * @return
     */
    @RequestMapping("list")
    public String list(Model model, @ModelAttribute("qo") TravelQuery qo) {
        PageInfo query = travelService.query(qo);
        model.addAttribute("pageInfo", query);
        return "travel/list";
    }

    /**
     * 修改发布状态
     * @return
     */
    @RequestMapping("changeState")
    @ResponseBody
    public Object changeState(int state, Long id ) {
        travelService.updateByState(state, id);
        return new AjaxResult();
    }

    @RequestMapping("getTravelContent")
    @ResponseBody
    public Object getTravelContent(Long id ) {

        TravelContent content = travelService.getContent(id);
        return new AjaxResult().addData(content.getContent());
    }

}

